﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.d01_jkdaMenu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void d01_jkda_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            d01_jkdaMgr mgr = new d01_jkdaMgr();
            e.Total = int.Parse(mgr.GetRecordCount_d01_jkda(e.Parameters[d01_jkda_Filter.ParamPrefix]));
            IList<d01_jkda> list = mgr.FindAllByPage_d01_jkda(e.Start.ToString(), e.Limit.ToString(), e.Parameters[d01_jkda_Filter.ParamPrefix]);
            d01_jkda_MainStore.DataSource = list;
            d01_jkda_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            d01_jkdaMgr mgr = new d01_jkdaMgr();
            RowSelectionModel sm = d01_jkda_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                d01_jkda _d01_jkda = new d01_jkda();
                _d01_jkda.jtbm = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_d01_jkda(_d01_jkda))
                {
                    log.Debug("d01_jkda中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            d01_jkda_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            d01_jkdaMgr mgr = new d01_jkdaMgr();
            d01_jkda _d01_jkda = new d01_jkda();
            if (Hid.Text.Length > 0)
                _d01_jkda = mgr.FindById_d01_jkda(int.Parse(Hid.Text));
            
			_d01_jkda.dzbm = Txtdzbm.Text.Trim();
			_d01_jkda.hbh = Txthbh.Text.Trim();
			_d01_jkda.rbh = Txtrbh.Text.Trim();
			_d01_jkda.hzxm = Txthzxm.Text.Trim();
			_d01_jkda.hzxb = Txthzxb.Text.Trim();
			_d01_jkda.brnl = Txtbrnl.Text.Trim();
			_d01_jkda.sfzh = Txtsfzh.Text.Trim();
			_d01_jkda.zbh = Txtzbh.Text.Trim();
			_d01_jkda.cbh = Txtcbh.Text.Trim();
			_d01_jkda.txdz = Txttxdz.Text.Trim();
			_d01_jkda.yzbm = Txtyzbm.Text.Trim();
			_d01_jkda.dhhm = Txtdhhm.Text.Trim();
			_d01_jkda.dzyx = Txtdzyx.Text.Trim();
			_d01_jkda.jtrs = Txtjtrs.Text.Trim();
			_d01_jkda.nyrs = int.Parse(TxtNumnyrs.Text.Trim());
			_d01_jkda.ssdq = Txtssdq.Text.Trim();
			_d01_jkda.chsx = Txtchsx.Text.Trim();
			_d01_jkda.hsx = Txthsx.Text.Trim();
			_d01_jkda.jzjb = Txtjzjb.Text.Trim();
			_d01_jkda.rcbz = Txtrcbz.Text.Trim();
			_d01_jkda.rcsj = Txtrcsj.Text.Trim();
			_d01_jkda.rcyy = Txtrcyy.Text.Trim();
			_d01_jkda.jhje = Txtjhje.Text.Trim();
			_d01_jkda.syje = Txtsyje.Text.Trim();
			_d01_jkda.hbz = int.Parse(TxtNumhbz.Text.Trim());
			_d01_jkda.jdsj = Txtjdsj.Text.Trim();
			_d01_jkda.ysmc = Txtysmc.Text.Trim();
			_d01_jkda.dabm = Txtdabm.Text.Trim();
			_d01_jkda.ylzh = Txtylzh.Text.Trim();
			_d01_jkda.csrq = Txtcsrq.Text.Trim();
			_d01_jkda.mz = Txtmz.Text.Trim();
			_d01_jkda.zy = Txtzy.Text.Trim();
			_d01_jkda.whzd = Txtwhzd.Text.Trim();
			_d01_jkda.hyzk = Txthyzk.Text.Trim();
			_d01_jkda.hklb = Txthklb.Text.Trim();
			_d01_jkda.jwx = Txtjwx.Text.Trim();
			_d01_jkda.jbmc = Txtjbmc.Text.Trim();
			_d01_jkda.ywjb = Txtywjb.Text.Trim();
			_d01_jkda.grs = Txtgrs.Text.Trim();
			_d01_jkda.jcnr = Txtjcnr.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_d01_jkda(_d01_jkda);
            else
                isok = mgr.Add_d01_jkda(_d01_jkda);
            if (isok)
            {
                d01_jkda_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("d01_jkda中执行了保存（插入或修改），并成功");
                d01_jkda_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}